<?php
header('Content-type:text/html;charset=utf8');
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-2-24
*/


class ManagerController extends Controller{
	
	/**
	 * 访问控制过滤
	 * @author xjh
	 */
	function filters(){
		return array(
			'accessControl'
		);
	}
	/**
	 * 具体方法访问具体条件
	 */
	
	function accessRules(){
		//匿名用户才可以访问login
		return array(
			array(
				'allow',
				'actions'=>array('Login'),
				'users'=>array('?'),
			),
			array(
				'allow',
				'actions'=>array('Logout'),
				'users'=>array('@'),
			),
			array(
				'deny',
				'users'=>array('*'),
			),
		);
	}
	
	
	/**
	 * 验证码
	 */
	function actions(){
		return array(
			'captcha' => array(//相当于./index.php?r=user/captcha
				'class' => 'system.web.widgets.captcha.CCaptchaAction',//路径引入类，路径的别名,不建议，因为会修复原框架bug
				'backColor' => 0xffffff, 
				'width' => 121,
				'height' => 47,
				'maxLength'=>4,
				'minLength'=>4,
				'offset' => 3,
				'transparent'=>true,
				'testLimit'=>0,//限制相同验证码出现的次数
		),
		);
	} 
	
	/**
	 * 登陆控制器
	 */
	function actionLogin(){
		$manager_model = new LoginForm();
//		if(isset($_POST['code']) && $_POST['code'] == 'mycode'){
//			if(Yii::app()->session['session_code'] != $_POST['C']){
//				echo 1;
//				exit;
//			}
//		}
		if(isset($_POST['LoginForm'])){
			$manager_model->attributes = $_POST['LoginForm'];
		
			//用户名密码判断和保存session
			if (Yii::app()->session['session_code'] != $_POST['code']){
				echo "验证码错误";
				exit;
			}
			if($manager_model->validate() && $manager_model->login()){
				//成功提示
				Yii::app()->user->setFlash('success','登陆成功');
				$this->redirect('./index.php?r=backweb/index/index');
			}
		}
		$this->renderPartial('login',array('manager_model'=>$manager_model));
	}
	
	/**
	 * 退出
	 */
	
	function actionLogout(){
		Yii::app()->session->clear();//删除内存里session变量信息
		Yii::app()->session->destroy();//删除服务器的session文件
		$this->redirect('./index.php?r=backweb/manager/login');
	}
	
}
?>
